// 回到上一页
// 从cookie取prev, 看是哪个path
// 从cookie找到对应path, 没有就直接跳转, 有就取值拼接参数再跳转

var backWithPrev = function (prev) {
    return function (e) {
        e = e ? e : window.event;
        var keyValue = e.which ? e.which : e.keyCode;
        switch (keyValue) {
            case 8:
            case 27:
                if (prev) {
                    if (prev === 'root') {
                        setTimeout(function () {
                            window.location.href = Cookies.get("epg_back_url") || "/recommend";
                        }, 0)
                    } else if (prev === 'search') {
                        setTimeout(function () {
                            window.location.href = Cookies.get("search_prev")
                        }, 0);
                    } else {
                        setTimeout(function () {
                            var params = Cookies.get(prev)

                            if (params) {
                                window.location.href = prev + params
                            } else {
                                window.location.href = prev
                            }
                        }, 0);
                    }
                } else {
                    setTimeout(function () {
                        var prevPath = Cookies.get('prev')
                        var params = Cookies.get(prevPath)

                        if (params) {
                            window.location.href = prevPath + params
                        } else {
                            window.location.href = prevPath
                        }
                    }, 0);
                }
                break;
        }
    };
};

var goRoot = backWithPrev('root');
